<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<meta name="renderer" content="webkit|ie-comp|ie-stand">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
<meta http-equiv="Cache-Control" content="no-siteapp" />
<!--[if lt IE 9]>
<script type="text/javascript" src="lib/html5shiv.js"></script>
<script type="text/javascript" src="lib/respond.min.js"></script>
<![endif]-->
<link rel="stylesheet" type="text/css" href="static/h-ui/css/H-ui.min.css" />
<link rel="stylesheet" type="text/css" href="static/h-ui.admin/css/H-ui.admin.css" />
<link rel="stylesheet" type="text/css" href="lib/Hui-iconfont/1.0.8/iconfont.css" />
<link rel="stylesheet" type="text/css" href="static/h-ui.admin/skin/default/skin.css" id="skin" />
<link rel="stylesheet" type="text/css" href="static/h-ui.admin/css/style.css" />
<!--[if IE 6]>
<script type="text/javascript" src="lib/DD_belatedPNG_0.0.8a-min.js" ></script>
<script>DD_belatedPNG.fix('*');</script>
<![endif]-->
<title>票务室管理</title>
</head>
<body>
<nav class="breadcrumb"><i class="Hui-iconfont">&#xe67f;</i> 首页
	<span class="c-gray en">&gt;</span>
	基础信息管理
	<span class="c-gray en">&gt;</span>
	票务室管理
	<a class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px" href="javascript:location.replace(location.href);" title="刷新" ><i class="Hui-iconfont">&#xe68f;</i></a>
</nav>
<div class="page-container">
<div class="text-c">  <!-- 日期范围： --> 
		<!-- <input type="text" onfocus="WdatePicker({ maxDate:'#F{$dp.$D(\'datemax\')||\'%y-%M-%d\'}' })" id="datemin" class="input-text Wdate" style="width:120px;">
		-
		<input type="text" onfocus="WdatePicker({ minDate:'#F{$dp.$D(\'datemin\')}',maxDate:'%y-%M-%d' })" id="datemax" class="input-text Wdate" style="width:120px;"> -->
		<!-- <input type="text" class="input-text" style="width:250px" placeholder="输入票务室名称" id="userName" name=""> -->
		分公司:
		<span class="select-box inline">
		<select class="select" id="comId" name="comId">
			<option value="">请选择分公司</option>
		</select>
		</span>
		票务室:
		<span class="select-box inline">
		<select class="select" id="toId" name="toId">
			<option value="">请选择票务室</option>
		</select>
		</span>
		
		<button type="submit" class="btn btn-success" id=""  onClick="queryOffice()" name=""><i class="Hui-iconfont">&#xe665;</i> 搜用户</button>
	</div>
	<div class="cl pd-5 bg-1 bk-gray mt-20">
		<span class="l">
			<a href="javascript:;" id="delectId" onclick="datadel()" class="btn btn-danger radius">
				<i class="Hui-iconfont">&#xe6e2;</i> 
				批量删除
			</a> 
		
			<a href="javascript:;" onclick="office_add()" class="btn btn-primary radius"><i class="Hui-iconfont">&#xe600;</i> 添加票务室</a>
			<!-- <span class="r" id="userLength"> -->
			</span> 
	</div>
	</div>
<!-- <div class="page-container" id="app">
	<div class="text-c">
		<input type="text" name="" id="query" placeholder="票务室名称、id" style="width:250px" class="input-text" v-model="msg">
		<button name="" id="" class="btn btn-success" type="submit" v-on:click="query()"><i class="Hui-iconfont">&#xe665;</i> 搜索</button>
	</div>
	<div class="mt-20">
		<table id="list" class="table table-border table-bordered table-hover table-bg table-sort">
		</table>
	</div>
</div> -->
	<div style="padding: 20px;">
		<table id="divListId" class="table table-border table-bordered table-bg table-hover table-sort">
			<thead>
				<tr class="text-c">
					<th id="thid"> <input type="checkbox"   style="float:left;"  name="officeId"></th>
					<th >所属公司</th>
					<th >部门名称</th>
					<th >所在地址</th>
					<th >集结中心</th>
					<!-- <th width="100">创建者</th> -->
					<th >状态</th>
					<th >操作</th>
				</tr>
			</thead>
		</table>
	</div>
<!--_footer 作为公共模版分离出去-->
<script type="text/javascript" src="lib/jquery/1.9.1/jquery.min.js"></script>
<script type="text/javascript" src="lib/layer/2.4/layer.js"></script>
<script type="text/javascript" src="static/h-ui/js/H-ui.min.js"></script>
<script type="text/javascript" src="static/h-ui.admin/js/H-ui.admin.js"></script>  <!--/_footer 作为公共模版分离出去-->

<!--请在下方写此页面业务相关的脚本-->
<script type="text/javascript" src="lib/My97DatePicker/4.8/WdatePicker.js"></script>
<script type="text/javascript" src="lib/datatables/1.10.0/jquery.dataTables.js"></script>
<script type="text/javascript" src="lib/laypage/1.2/laypage.js"></script>
<script type="text/javascript" src="js/jquery.base64.js"></script>
<script type="text/javascript" src="js/vue.js" charset="utf-8"></script>
<script type="text/javascript">
/*系统-票务室-添加*/
function system_category_add(title,url,w,h){
	layer_show(title,url,w,h);
}
/*系统-票务室-编辑*/
function system_category_edit(title,url,id,w,h){
	layer_show(title,url,w,h);
}
/*系统-票务室-删除*/
function system_category_del(obj,id){
	layer.confirm('确认要删除吗？',function(index){
		$.ajax({
			type: 'POST',
			url: '',
			dataType: 'json',
			success: function(data){
				$(obj).parents("tr").remove();
				layer.msg('已删除!',{icon:1,time:1000});
			},
			error:function(data) {
				console.log(data.msg);
			},
		});
	});
}
</script>

<script type="text/javascript">

	var comId;
	var toId;
	$(function(){
		var username =window.localStorage.getItem("user_name");	
		var myArray;
		
		if(username!="admin"){
			$("#delectId").attr("style","display:none;");
		}
	
		$.ajax({
			type: 'get',
			url: report_service+'/getAllCompany',
			 beforeSend: function (request) {
							request.setRequestHeader("Authorization", "Bearer " + getToken());
						}, 
			dataType: 'json',
			async: false,
			success: function(data){
				var list =  eval('(' + data.list + ')');
				for(var i = 0;i<list.length;i++){
					$("#comId").append("<option value='"+list[i].companyid+"'>"+list[i].companyname+"</option>");				
				}
			},
			error: function(data){
				console.log(data.msg);
			}
		});
		
		$.ajax({
			type: 'get',
			url: report_service+'/getUserByname',
			data:{
				"username":username
			},
			async: false,
			beforeSend: function (request) {
							request.setRequestHeader("Authorization", "Bearer " + getToken());
						}, 
			dataType: 'json',
			success: function(data){
				console.log(""+data.list);
				var list =  eval('(' + data.list + ')');
				console.log(list)
				if(list[0].officeId.indexOf("1")==0){
					$("#comId").val(list[0].companyId);
					comId = list[0].companyId;
					/* var comLength = $("#comId option").length;
					console.log($("#comId option[index='"+i+"']").val); */
					
					$.ajax({
						type: 'get',
						url: report_service+'/getTicktOfficeByCom',
						 beforeSend: function (request) {
										request.setRequestHeader("Authorization", "Bearer " + getToken());
									}, 
						data:{
							"comId":comId
						},
						cache:false,    
						dataType:'json',
						async: false,
						success: function(data){
							//var list = data.list;
							var list =  eval('(' + data.list + ')');
							for(var i=0;i<list.length;i++){
								var option = '<option value="'+list[i].toiid+'">'+list[i].toiname+'</option>';
								$("#toId").append(option);
							}
						},
						error:function(){
							alert("请求失败");
						}
					});
					$("#toId").val(list[0].officeId);
					toId = list[0].officeId;
					$("#comId").attr("disabled","disabled");
					$("#toId").attr("disabled","disabled");
				}
				if(list[0].officeId.indexOf("1") == -1  && list[0].companyId.indexOf("1")==0 ){
					$("#comId").val(list[0].companyId);
					comId = list[0].companyId;
					$.ajax({
						type: 'get',
						url: report_service+'/getTicktOfficeByCom',
						 beforeSend: function (request) {
										request.setRequestHeader("Authorization", "Bearer " + getToken());
									}, 
						data:{
							"comId":comId
						},
						cache:false,    
						dataType:'json',
						async: false,
						success: function(data){
							//var list = data.list;
							var list =  eval('(' + data.list + ')');
							for(var i=0;i<list.length;i++){
								var option = '<option value="'+list[i].toiid+'">'+list[i].toiname+'</option>';
								$("#toId").append(option);
							}
						},
						error:function(){
							alert("请求失败");
						}
					});
					$("#comId").attr("disabled","disabled");
				}
				
				
				
				
			},
			error: function(data){
				console.log(data.msg);
			}
		});
		
		//getCashboxBy();
		queryOffice();
	});
	
	$("#comId").change(function(){
		$("#toId").empty();
		var comId = $(this).val();
		var targetUrl = report_service+'/getTicktOfficeByCom';
		if(comId == ''){
			//$("#toId").fadeOut("slow");
			return;
		}
		$.ajax({
			type: 'get',
			url: targetUrl,
			 beforeSend: function (request) {
							request.setRequestHeader("Authorization", "Bearer " + getToken());
						}, 
			data:{
				"comId":comId
			},
			cache:false,    
			dataType:'json',  
			success: function(data){
				//var list = data.list;
				var list =  eval('(' + data.list + ')');
				var option2 = '<option value="">请选择</option>';
				$("#toId").append(option2);
				
				for(var i=0;i<list.length;i++){
					var option = '<option value="'+list[i].toiid+'">'+list[i].toiname+'</option>';
					$("#toId").append(option);
				}
			},
			error:function(){
				alert("请求失败");
			}
		});
	});
	
	
	function queryOffice(){
		//var userName=document.getElementById("userName").value;
		var comId =  $("#comId").val();
		var officeId =  $("#toId").val();
		console.log(comId)
		$.ajax({
			type: 'post',
			url: abnormalreport_service+'office/queryOfficeAll',
			data: {
				comId:comId,
				officeId:officeId
			},
			dataType: 'json',
		 	beforeSend: function (request) {
									request.setRequestHeader("Authorization", "Bearer " + getToken());
								}, 
			success: function(data){
				console.log(data)
						$('#divListId').DataTable( {
							   data: data.list,
							  // data2: data.companyList,
							   //使用对象数组，一定要配置columns，告诉 DataTables 每列对应的属性
							   //data 这里是固定不变的，name，position，salary，office 为你数据里对应的属性
							   destroy:true,
							   "lengthMenu":[10, 50, 100],
							   "pageLength": 100,
							   columns: [
								    {data: 'id'  },
									{ data: 'companyname' },
								    { data: 'officename'},
									{ data: 'address'},
									{ data: 'rallyingPoint'},
									//{ data: 'createTime' },
									//{ data: 'create' },
								    { data: 'status'},
									 { data: 'status'},
								   
							   ],
							  columnDefs: [
								 // +'<td><a href="javascript:;" onclick="admin_add(\''+list[i].id+'\')" class="btn btn-primary radius"><i class="Hui-iconfont">&#xe600;</i> 审核</a></td>'
								
								{
									"orderable": false,
								    "targets": 0
								},
								{
								     "targets": 0,//
								     "data": null,
								     render: function(data, type, row, meta) {
										//document.getElementById("thid").setAttribute("class","");
								  		return '<input type="checkbox" value='+data+'  style="float:left;"  name="officeId">'
						
								     }
								  }  ,
								  {
								     "targets": 5,//
								     "data": null,
								     render: function(data, type, row, meta) {
								  										 
										 if(data==0){
											//return'<td><a href="javascript:;" onclick="admin_add(\''+data.id+'\')" class="btn btn-primary radius"><i class="Hui-iconfont">&#xe600;</i> 审核</a></td>'
											return '<td>停用</td>'								   
										 }else if(data==1){
											return '<td>启用</td>'
										 }else{
											return '<td>停用</td>'
										 }
								     }
								  }  ,
								  {
								     "targets": -1,//
								     "data": null,
								     render: function(data, type, row, meta) {
										 
										if(data==0){
											return ' <div class="cl">'+
												'<span class="l">'+
												//'<a href="javascript:;" onclick="admin_stop(\''+row.id+'\')" class="btn btn-danger radius"><i class="Hui-iconfont">&#xe6e2;</i>停用</a>'+
												'<a style="text-decoration:none" onClick="admin_start(\''+row.id+'\')" href="javascript:;" title="启用"><i class="Hui-iconfont">&#xe615;</i></a>'+
												'<a  style="text-decoration:none"href="javascript:;" onclick="office_addType(\''+row.id+'\')" title="绑定"><i class="Hui-iconfont">&#xe604</i></a>'+
												'<a style="text-decoration:none" href="javascript:;" onclick="office_updateById(\''+row.id+'\')"  title="修改"><i class="Hui-iconfont">&#xe6df;</i></a></span>'+
											'</div>' 
										}else if(data==1){
											 return ' <div class="cl">'+
												'<span class="l">'+
												'<a style="text-decoration:none" onClick="admin_stop(\''+row.id+'\')" href="javascript:;" title="停用"><i class="Hui-iconfont">&#xe631;</i></a>'+
												//'<a style="text-decoration:none" onClick="admin_start(\''+row.id+'\')" href="javascript:;" title="启用"><i class="Hui-iconfont">&#xe631;</i></a>'+
												'<a  style="text-decoration:none"href="javascript:;" onclick="office_addType(\''+row.id+'\')" title="绑定"><i class="Hui-iconfont">&#xe604</i></a>'+
												'<a style="text-decoration:none" href="javascript:;" onclick="office_updateById(\''+row.id+'\')"  title="修改"><i class="Hui-iconfont">&#xe6df;</i></a></span>'+
											 '</div>' 
										}
										
													
								     }
								  }  ,
								  ]
						   } );
						   document.getElementById("thid").setAttribute("class","");
			},
			error:function(data) {
				console.log(data.msg);
			},
		});
		
	}
	
	
	
	function queryCompany(){
			$.ajax({
				type: 'POST',
				url: abnormalreport_service+'office/getAllCompany',
				dataType: 'json',
			 	beforeSend: function (request) {
										request.setRequestHeader("Authorization", "Bearer " + getToken());
									}, 
				success: function(data){
				//	var list =  eval('(' + data.list + ')');
				var list =data.list;
				console.log(list.length)
					for(var i = 0;i<list.length;i++){
						$("#comId").append("<option value='"+list[i].companyid+"'>"+list[i].companyname+"</option>");				
					}
					queryOffice();	
				},
				error: function(data){
					console.log(data.msg);
				}
			});
		
	}
		
	function office_add (){
		layer_show("新增","a_baseinfo-office_add.html",800,400);
		
	}
	function office_addType (id){
		var a = id;
		layer_show("绑定","a_baseinfo-office_add_type.html?id="+a+"",500,200);
	}
	
	function office_updateById (id){
		var a = id;
		layer_show("修改","a_baseinfo-office_update.html?id="+a+"",800,400);
	}
	
	
	
	function datadel (){
					var chk_value =[];//定义一个数组    
					var ids = "";
					$('input[name="officeId"]:checked').each(function(){//遍历每一个名字为interest的复选框，其中选中的执行函数    
					chk_value.push($(this).val());//将选中的值添加到数组chk_value中   
						ids=ids+$(this).val()+","
					});
					
					if(ids==""){
						alert("选项不能为空")
						return;
					}
					
					layer.confirm('确认要删除？', function(index) {
						$.ajax(abnormalreport_service+'office/delOfficeById',{
							data:{
								"ids":ids
							},
							 beforeSend: function (request) {
													request.setRequestHeader("Authorization", "Bearer " + getToken());
												}, 
							dataType: 'json',
							type: 'post',
							//timeout:3000,//超时时间设置为10秒；
							success: function(data) {
							
							window.location.reload()//刷新当前页面.
							},
							error: function(e) {
							
							}
						});	
					});
						
					
				
				
	}
	
	
	
	/*管理员-停用*/
	function admin_stop(id){
		layer.confirm('确认要停用吗？',function(index){
			var type='0'
			
			$.ajax(abnormalreport_service+'office/updateOfficeById',{
				data:{
					id:id,
					type:type
				},
				 beforeSend: function (request) {
										request.setRequestHeader("Authorization", "Bearer " + getToken());
									}, 
				dataType: 'json',
				type: 'post',
				//timeout:3000,//超时时间设置为10秒；
				success: function(data) {
					window.location.reload()//刷新当前页面.
					//window.location.reload()//刷新当前页面.
				},
				error: function(e) {
				
				}
			});
			layer.msg('已停用!',{icon: 5,time:1000});
		});
	}
	
	/*管理员-启用*/
	function admin_start(id){
		layer.confirm('确认要启用吗？',function(index){
				var type='1'
				
				$.ajax(abnormalreport_service+'office/updateOfficeById',{
				data:{
					id:id,
					type:type
				},
			 	beforeSend: function (request) {
										request.setRequestHeader("Authorization", "Bearer " + getToken());
									},
				dataType: 'json',
				type: 'post',
				//timeout:3000,//超时时间设置为10秒；
				success: function(data) {
				window.location.reload()//刷新当前页面.
				//window.location.reload()//刷新当前页面.
				},
				error: function(e) {
				
				}
			});
			
			layer.msg('已启用!', {icon: 6,time:1000});
		});
	}
	
</script>
</body>
</html>